﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;


namespace DemoPersonalizeSearch
{
    public static class MySessionExtension
    {
        public static bool IsLogin(this  HttpSessionState session)
        {
            if (session["UserLogin"] != null)
                return true;
            else return false; 
        }
        public static void AddUserLogin(this HttpSessionState session,string username)
        {
            session["UserLogin"]= username;
            DeliciousDatabaseDataContext db = new DeliciousDatabaseDataContext();
            UserData ud = db.UserDatas.Where(x => x.Username == username).FirstOrDefault();
            session["UserLoginData"] = ud;
                
        }
        public static string UserLogin(this HttpSessionState session)
        {
            if (session["UserLogin"] != null)
            {
                return session["UserLogin"].ToString();
            }
            else return "";
        }
        public static UserData UserLoginData(this HttpSessionState session)
        {


            return (UserData)session["UserLoginData"];
            
        }
        public static void RemoveLogin(this HttpSessionState session)
        {
            session.Remove("UserLogin");
        }

        //updown Options
        public static Option getOptions(this HttpSessionState session) {
            if (session["SearchOptions"] != null)
                return (Option)session["SearchOptions"];
            else return new Option();
            
        }
        
        public static void setOptions(this HttpSessionState session, Option opt)
        {
            session["SearchOptions"] = opt;

        }
        
    }
}